﻿<Window x:Class="YogaDictionary.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ignore="http://www.ignore.com"
        mc:Ignorable="d ignore"
        MinHeight="125"
        MinWidth="190"
        Height="400"
        Width="300"
        Title="Йога Словарь"
        DataContext="{Binding Main, Source={StaticResource Locator}}">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins\MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
        
    <Grid x:Name="LayoutRoot" Margin="5,5,5,5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="45" />
        </Grid.RowDefinitions>

        <ListView Grid.Row="0" 
                  x:Name="WordsBox"
                  ItemsSource="{Binding AllWords}"
                  ItemContainerStyle="{DynamicResource WordsListViewItemStyle}"
                  HorizontalContentAlignment="Stretch"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  SelectionChanged="SearchTextBox_OnSelectionChanged"
                  SelectedItem="{Binding SelectedWord}"
                  SelectionMode="Single">
            
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.InputBindings>
                            <MouseBinding 
                                Gesture="LeftDoubleClick" 
                                Command="{Binding DataContext.ShowNewDefinitionCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
                                CommandParameter="{Binding SelectedItem, ElementName=WordsBox, Mode=OneWay}" />
                        </Grid.InputBindings>
                        <TextBlock Text="{Binding Value}" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>

            <ListView.InputBindings>
                <KeyBinding Key="Enter" 
                    Command="{Binding ShowNewDefinitionCommand}"
                    CommandParameter="{Binding SelectedItem, ElementName=WordsBox}" />
            </ListView.InputBindings>
        </ListView>

        <Grid Grid.Row="1" x:Name="LayoutBottom" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="100"/>
            </Grid.ColumnDefinitions>

            <TextBox Grid.Column="0" 
                    x:Name="SearchTextBox"
                    Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}"  
                    VerticalContentAlignment="Center" 
                    TextWrapping="Wrap"
                    Focusable="True">
                <TextBox.InputBindings>
                    <KeyBinding Key="Enter" 
                                Command="{Binding ShowNewDefinitionCommand}"
                                CommandParameter="{Binding SelectedItem, ElementName=WordsBox}" />
                </TextBox.InputBindings>
            </TextBox>
            <Button Grid.Column="1" Content="Определение" Command="{Binding ShowNewDefinitionCommand}" CommandParameter="{Binding SelectedItem, ElementName=WordsBox}" Background="#FFDDDDDD"/>
        </Grid>
    </Grid>

</Window>
